# -*- coding:utf-8 -*-
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

# class Solution:
#     # 返回二维列表，内部每个列表表示找到的路径
#     def FindPath(self, root, e):
#         # write code here
#         self.res = []
#         if not root:
#             return []
#         self.t = e
#         a = [root.val]
#         self.help(root, a)
#         return self.res
#
#     def help(self, node, path):
#         if not node.left and not node.right and sum(path) == self.t:
#             self.res.append(path)
#         if node.left:
#             self.help(node.left, path.append(node.left.val))
#         if node.right:
#             self.help(node.right, path.append(node.right.val))


class Solution:
    # 返回二维列表，内部每个列表表示找到的路径
    def FindPath(self, root, e):
        # write code here
        a = [root.val]
        self.res = []
        self.v = 0
        if not root or e<0:
            return [[]]
        self.help(root,e-root.val,a)
        return self.res

    def help(self,node,e,a):
        if e==0 and node.left==None and node.right==None:
            self.res.append(a)
        if node.left:
            self.help(node.left,e-node.left.val,a+[node.left.val])
        if node.right:
            self.help(node.right,e-node.right.val,a+[node.right.val])


pNode1 = TreeNode(10)
pNode2 = TreeNode(5)
pNode3 = TreeNode(12)
pNode4 = TreeNode(4)
pNode5 = TreeNode(7)


pNode1.left = pNode2
pNode1.right = pNode3
pNode2.left = pNode4
pNode2.right = pNode5


S = Solution()
print(S.FindPath(pNode1, 22))
# 测试用例：[1,-2,-3,1,3,-2,null,-1]  -1
# 测试用例：[-2, None, -3] -5